using System;
using System.Collections.Generic;

namespace Caramel
{
	public class MemberComparer<T, TProperty> : IEqualityComparer<T>
	{
		private Func<T, TProperty> _selector;

		public MemberComparer(Func<T, TProperty> selector)
		{
			_selector = selector;
		}

		#region IEqualityComparer<T> Members

		public bool Equals(T x, T y)
		{
			return _selector(x).Equals(_selector(y));
		}

		public int GetHashCode(T x)
		{
			return _selector(x).GetHashCode();
		}

		#endregion
	}
}
